package callback

type EventType string

const (
	TaskStart   EventType = "TaskStart"
	TaskProcess EventType = "TaskProcess"
	TaskFinish  EventType = "TaskFinish"
	Stats       EventType = "Stats"
)

type Event struct {
	EventType EventType `json:"event_type"`
	EventData []byte    `json:"event_data"`
	EventTime int64     `json:"event_time"`
}

type Message interface {
	GetType() EventType
	GetAppId() string
	GetTaskId() string
}

type TaskBaseData struct {
	AppId  string `json:"app_id"`
	TaskId string `json:"task_id"`
}

func (d *TaskBaseData) GetAppId() string {
	return d.AppId
}
func (d *TaskBaseData) GetTaskId() string {
	return d.TaskId
}

type TaskStartData struct {
	TaskBaseData
	Executor string `json:"executor"`
}

func (d *TaskStartData) GetType() EventType {
	return TaskStart
}

type TaskProcessData struct {
	TaskBaseData
	Executor   string `json:"executor"`
	FileSize   int    `json:"file_size"`
	TotalPages int    `json:"total_pages"`
	CurPages   int    `json:"cur_pages"`
}

func (d *TaskProcessData) GetType() EventType {
	return TaskProcess
}

type TaskFinishData struct {
	TaskBaseData
	Success bool   `json:"success"`
	Result  Result `json:"result"`
	ErrCode int    `json:"err_code"`
	ErrMsg  string `json:"err_msg"`
}

func (d *TaskFinishData) GetType() EventType {
	return TaskFinish
}

type Result struct {
	FileName      string  `json:"file_name"`
	FileID        string  `json:"file_id"`
	Images        []Image `json:"images"`
	Width         int     `json:"width"`
	Height        int     `json:"height"`
	TranscodeMode int     `json:"transcode_mode"`
}

type Image struct {
	PageID       int    `json:"page_id"`
	Img          string `json:"img"`
	ThumbnailUrl string `json:"thumbnail_url"`
}
